package ee.maoinvest.frontend.controller.command.enterpriseCommands;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ee.maoinvest.backend.model.data.Enterprise;
import ee.maoinvest.backend.services.EnterpriseService;
import ee.maoinvest.backend.services.implementations.EnterpriseServiceImpl;
import ee.maoinvest.frontend.controller.command.Command;

public class GetAllEnterprisesThatAreNotWrittenOffCommand implements Command
{
	private Logger logger = Logger.getLogger(GetAllEnterprisesThatAreNotWrittenOffCommand.class);
	private int operationResult = 0;
	private final int OPERATION_SUCCESSFUL = 1;
	private final int OPERATION_UNSUCCESSFUL = 0;
	private final int PROBABLY_A_DATABASE_ERROR = -1;
	
	@Override
	public int executeCommand(HttpServletRequest request,
			HttpServletResponse response)
	{
		List<Enterprise> listOfEnterprises = null;
		EnterpriseService enterpriseService = null;
		
		try 
		{
			enterpriseService = new EnterpriseServiceImpl();
			listOfEnterprises = enterpriseService.getAllEnterprisesThatAreNotWrittenOff();
			request.setAttribute("listOfEnterprises", listOfEnterprises);
			operationResult = OPERATION_SUCCESSFUL;
				
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			return PROBABLY_A_DATABASE_ERROR;
		}
		
		return operationResult;
	}
}